package com.utils;

import com.dto.Page;
import com.dto.UserAndRoleDecn;
import com.entity.Role;
import com.entity.UserInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yadasu
 * @date 2020/12/29 13:53
 */

public class PageUtils {

    public static  Page<UserAndRoleDecn> pages(List<UserInfo> all){

        List<UserAndRoleDecn> list = new ArrayList<>();
        for (UserInfo userInfo : all) {
            UserAndRoleDecn userAndRoleDecn = new UserAndRoleDecn();
            userAndRoleDecn.setId(userInfo.getId());
            userAndRoleDecn.setNickname(userInfo.getNickname());
            userAndRoleDecn.setUsername(userInfo.getUsername());
            userAndRoleDecn.setEmail(userInfo.getEmail());
            userAndRoleDecn.setPhone(userInfo.getPhone());
            userAndRoleDecn.setEnabled(userInfo.isEnabled());
            List<Role> roles = userInfo.getRoles();
            for (Role role : roles) {
                userAndRoleDecn.setName_zh(role.getNameZh());
                list.add(userAndRoleDecn);
            }
        }
        Page<UserAndRoleDecn> page = new Page<>();
        page.setDatas(list);
        return page;
    }
}
